/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 10/20/2009
 * Time: 9:11 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using popLib;
using System.IO;
using System.Data.OleDb;
using System.Data;
using System.Collections;

namespace GenerateAccessTable
{
	/// <summary>
	/// Description of DBReader.
	/// </summary>
	public class DBReader
	{		
		public DBReader(string database, string password)
		{
			string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+database+";"+ (StringLib.isValid(password)?"Jet OLEDB:Database Password="+password+";":"");
			ArrayList arrTables = new ArrayList();
			DataTable SchemaTable;
			
			//Get all tables name
			using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                try
                {
                    // open the connection to the database 
                    conn.Open();

                    // Get the Tables
                    SchemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });

                    // Store the table names in the class scoped array list of table names
                    for (int i = 0; i < SchemaTable.Rows.Count; i++)
                        arrTables.Add(SchemaTable.Rows[i].ItemArray[2].ToString());
                    
                }catch (Exception ex)
                {
                    // break and notify if the connection fails
                    FormLib.alert(ex.Message, "Connection Error");
                }
			}			
		}
	}
	
	
}
